//
//  SISSTenancyContractShowViewController.m
//  SISSAPP
//
//  Created by 袁应荣 on 2019/7/5.
//  Copyright © 2019 优房网. All rights reserved.
//

#import "SISSTenancyContractShowViewController.h"
#import "SISSUploadTenancyContractViewController.h"
#import "SISSRentOutProgressModel.h"
#import "SISSRentOutProgressRecordInfoModel.h"
#import "SISSTenantProgressModel.h"
#import "SISSTenantProgressRecordInfoModel.h"
#import "SISSNetworkingManager+Progress.h"
#import "SISSTenancyContractModel.h"

@interface SISSTenancyContractShowViewController ()

/// 租赁及经纪合同模型
@property (strong, nonatomic) SISSTenancyContractModel *tenancyContractModel;

@end

@implementation SISSTenancyContractShowViewController

- (void)viewDidLoad {
    
    self.isHiddenDateChooseView = YES;
    
    [super viewDidLoad];
    
    self.title = @"物业租赁及经纪合同";
    [self requestTenancyContractData];
}

- (void)requestTenancyContractData {
    NSString *albpId = self.rentOutProgressModel ? self.rentOutProgressModel.albpId : self.tenantProgressRecordInfoModel.albpId;
    NSString *arbpId = self.tenantProgressModel ? self.tenantProgressModel.arbpId : self.rentOutProgressRecordInfoModel.arbpId;
    NSInteger leaseType = self.rentOutProgressModel ? 1 : self.tenantProgressRecordInfoModel.tradeBusinessType;
    NSInteger rentType = self.tenantProgressModel ? 1 : self.rentOutProgressRecordInfoModel.tradeBusinessType;
    if (rentType == 2) arbpId = self.rentOutProgressRecordInfoModel.arrId;
    if (leaseType == 2) albpId = self.tenantProgressRecordInfoModel.alrId;
    NSDictionary *parameters = @{
                                 @"albpId" : albpId,
                                 @"arbpId" : arbpId
                                 };
    WeakSelf
    if (self.rentOutProgressModel) {
        [kNetworkManager requestTenancyContractWithParameters:parameters success:^(SISSTenancyContractModel *tenancyContractModel) {
            
            weakSelf.tenancyContractModel = tenancyContractModel;
            weakSelf.uploadImageShowView.imageUrlArr = tenancyContractModel.image.mutableCopy;
            weakSelf.createDateView.rightStr = tenancyContractModel.insertTime;
            weakSelf.remarkView.rightStr = tenancyContractModel.otherdesc;
            
        } failed:^(NSError *error) {
            NSLog(@"%@",error);
        }];
    } else if (self.tenantProgressModel) {
        [kNetworkManager requestTenantProgressTenancyContractWithParameters:parameters success:^(SISSTenancyContractModel *tenancyContractModel) {
            
            weakSelf.tenancyContractModel = tenancyContractModel;
            weakSelf.uploadImageShowView.imageUrlArr = tenancyContractModel.image.mutableCopy;
            weakSelf.createDateView.rightStr = tenancyContractModel.insertTime;
            weakSelf.remarkView.rightStr = tenancyContractModel.otherdesc;
            
        } failed:^(NSError *error) {
             NSLog(@"%@",error);
        }];
    }
    
}

- (void)modifyButtonClickAction {
    SISSUploadTenancyContractViewController *vc = [[SISSUploadTenancyContractViewController alloc] init];
    vc.rentOutProgressModel = self.rentOutProgressModel;
    vc.rentOutProgressRecordInfoModel = self.rentOutProgressRecordInfoModel;
    vc.tenantProgressModel = self.tenantProgressModel;
    vc.tenantProgressRecordInfoModel = self.tenantProgressRecordInfoModel;
    vc.tenancyContractModel = self.tenancyContractModel;
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)initConstraint {
    [super initConstraint];
    self.contractNoView.hidden = YES;
    WeakSelf
    [self.remarkView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.containerView).offset(globelMargin);
        make.left.right.equalTo(weakSelf.containerView);
        make.height.mas_equalTo(5.5 * globelMargin);
    }];
    
    [self.uploadImageShowView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.createDateView.mas_bottom).offset(2 * globelMargin);
    }];
}

@end
